//取得cookie    
function getCookie(name) {    
 var nameEQ = name + "=";
 var ca = document.cookie.split(';');    //把cookie分割成组    
 for(var i=0;i < ca.length;i++) {    
 var c = ca[i];                      //取得字符串    
 while (c.charAt(0)==' ') {          //判断一下字符串有没有前导空格    
 c = c.substring(1,c.length);      //有的话，从第二位开始取    
 }    
 if (c.indexOf(nameEQ) == 0) {       //如果含有我们要的name    
 return unescape(c.substring(nameEQ.length,c.length));    //解码并截取我们要值    
 }    
 }    
 return false;  

}    
   
//清除cookie    
function clearCookie(name) {    
 setCookie(name, "", -1);    
}    
    
//设置cookie    
function setCookie(name, value, seconds) {    
 seconds = seconds || 0;   //seconds有值就直接赋值，没有为0，这个根php不一样。    
 var expires = "";    
 if (seconds != 0 ) {      //设置cookie生存时间    
 var date = new Date();    
 date.setTime(date.getTime()+(seconds*1000));    
 expires = "; expires="+date.toGMTString();    
 }    
 document.cookie = name+"="+escape(value)+expires+"; path=/";   //转码并赋值    
}
function savelogininfo(n1,n2,t){
	var info=getlogininfo();
	var str='';
	if(t){str=n1+'#PSI#'+n2;}else{str=n1+'#PSI#';}
	if(info){
		for(var i=0;i<info.length;i++){
			if(info[i].indexOf(n1)<=-1){
				str+='#LGI#'+info[i];
			}
		}
	}
	clearCookie('mylogininfo');
	setCookie('mylogininfo',str,30*24*60*60);
}
function splitlogininfo(ts){
	var info;
	if(ts && ts!=''){
		info=ts.split('#PSI#');
	}
	return info;
}
function getlogininfopass(us,id3,id4){
	var info=getlogininfo();
	if(info){
		var pas='',check=false;
		for(var i=0;i<info.length;i++){
			if(info[i].indexOf(us+'#PSI#')>-1){
				var up=splitlogininfo(info[i]);
				if(up){
					pas=up[1];
					if(pas&&pas!=''){
						check=true;
					}
				}
				break;
			}
		}
	}
	document.getElementById(id3).value=pas;
	document.getElementById(id4).checked=check;
	return;
	
}
function readlogininfo(id1,id2,id3,id4){
	var info=getlogininfo();
	if(info){
		var us1='',pas1='',check1=false,dd='';
		for(var i=0;i<info.length;i++){
			var up=splitlogininfo(info[i]);
			if(up){
				if(i==0){
					us1=up[0];pas1=up[1];
					if(pas1&&pas1!=''){
						check1=true;
					}
				}
				dd+='<dd>'+up[0]+'</dd>'
			}
		}
		document.getElementById(id1).value=us1;
		document.getElementById(id2).innerHTML=dd;
		document.getElementById(id3).value=pas1;
		document.getElementById(id4).checked=check1;
	}
	return;
}
var mylogininfo;
function getlogininfo(){
	if(!mylogininfo){
		var str=getCookie('mylogininfo');
		if(str || str!=''){
			mylogininfo=str.split('#LGI#');
		}
	}
	return mylogininfo;
}

